package fruitshopmall.Controller;


import fruitshopmall.Entity.News;
import fruitshopmall.Service.NewsService;
import fruitshopmall.base.BaseController;
import fruitshopmall.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 公告管理
 */
@Controller
@RequestMapping("/news")
public class NewsController extends BaseController {

    @Autowired
    private NewsService newsService;

    /**
     * 公告列表
     * @return
     */
    @RequestMapping("/findBySql")
    @ResponseBody
    public Pager<News> findBySql(News news, Model model){
        String sql = "select * from news where 1=1 ";
        if(!isEmpty(news.getName())){
            sql += " and name like '%"+news.getName()+"%'";
        }
        sql += " order by id desc";
        Pager<News> pagers = newsService.findBySqlRerturnEntity(sql);
        System.out.println(pagers);
/*        model.addAttribute("pagers",pagers);
        model.addAttribute("obj",news);*/
        return pagers;
    }


}
